qlist = (int*) xcalloc(nelems, sizeof(*qlist));
#if NEWQ
- foreach(Waypoint* waypointp, waypt_list) {
+ foreach (Waypoint* waypointp, waypt_list) {
comp[i] = waypointp;
#else
QUEUE_FOR_EACH(q, elem, tmp) {
}
static void
-position_process_route(const route_head* rh)
+position_process_any_route(const route_head* rh, int type)
{
int i = rh->rte_waypt_ct;
if (i) {
cur_rte = (route_head*)rh;
- position_runqueue((queue*)&rh->waypoint_list, i, rtedata);
+ position_runqueue((queue*)&rh->waypoint_list, i, type);
cur_rte = NULL;
}
}
+static void
+position_process_rte(const route_head* rh)
+{
+ position_process_any_route(rh, rtedata);
+}
+
+static void
+position_process_trk(const route_head* rh)
+{
+ position_process_any_route(rh, trkdata);
+}
+
static void
position_noop_w(const Waypoint*)
{
position_runqueue(&waypt_head, i, wptdata);
}
- route_disp_all(position_process_route, position_noop_t, position_noop_w);
- track_disp_all(position_process_route, position_noop_t, position_noop_w);
+ route_disp_all(position_process_rte, position_noop_t, position_noop_w);
+ track_disp_all(position_process_trk, position_noop_t, position_noop_w);
}
void
queue* elem, *tmp;
Waypoint* wpt;
- double oldlat = -999;
- double oldlon = -999;
- time_t oldtime = 0;
- int first = 1;
+ double last_course_lat;
+ double last_course_lon;
+ double last_speed_lat;
+ double last_speed_lon;
+ time_t last_speed_time;
+ int first;
fix_type fix;
int nsats = 0;
}
if (first) {
if (opt_course) {
+ // TODO: the course value 0 isn't valid, wouldn't it be better to UNSET course?
WAYPT_SET(wpt, course, 0);
}
if (opt_speed) {
+ // TODO: the speed value 0 isn't valid, wouldn't it be better to UNSET speed?
WAYPT_SET(wpt, speed, 0);
}
first = 0;
+ last_course_lat = wpt->latitude;
+ last_course_lon = wpt->longitude;
+ last_speed_lat = wpt->latitude;
+ last_speed_lon = wpt->longitude;
+ last_speed_time = wpt->GetCreationTime().toTime_t();
} else {
if (opt_course) {
- WAYPT_SET(wpt, course, heading_true_degrees(RAD(oldlat),
- RAD(oldlon),RAD(wpt->latitude),
+ WAYPT_SET(wpt, course, heading_true_degrees(RAD(last_course_lat),
+ RAD(last_course_lon),RAD(wpt->latitude),
RAD(wpt->longitude)));
+ last_course_lat = wpt->latitude;
+ last_course_lon = wpt->longitude;
}
if (opt_speed) {
- if (oldtime != wpt->GetCreationTime().toTime_t()) {
+ if (last_speed_time != wpt->GetCreationTime().toTime_t()) {
+ // If we have mutliple points with the same time and
+ // we use the pair of points about which the time ticks then we will
+ // underestimate the distance and compute low speeds on average.
+ // Therefore, if we have multiple points with the same time use the
+ // first ones with the new times to compute speed.
+ // Note that points with the same time can occur because the input
+ // has truncated times, or because we are truncating times with
+ // toTime_t().
WAYPT_SET(wpt, speed, radtometers(gcdist(
- RAD(oldlat), RAD(oldlon),
+ RAD(last_speed_lat), RAD(last_speed_lon),
RAD(wpt->latitude),
RAD(wpt->longitude))) /
- labs(wpt->GetCreationTime().toTime_t()-oldtime));
+ labs(wpt->GetCreationTime().toTime_t()-last_speed_time));
+ last_speed_lat = wpt->latitude;
+ last_speed_lon = wpt->longitude;
+ last_speed_time = wpt->GetCreationTime().toTime_t();
} else {
WAYPT_UNSET(wpt, speed);
}
}
}
- oldlat = wpt->latitude;
- oldlon = wpt->longitude;
- oldtime = wpt->GetCreationTime().toTime_t();
}
}
}